<?php
include("../models/webconfig.php");
include("../models/class.connection.php");
include("../models/entities/class.ProductEntity.php");
include("../models/repositories/class.ProductRepository.php");
include("../models/entities/class.CategoryEntity.php");
include("../models/repositories/class.CategoryRepository.php");
include("../models/entities/class.SectionEntity.php");
include("../models/repositories/class.SectionRepository.php");
include("../models/entities/class.AccountEntity.php");
include("../models/repositories/class.AccountRepository.php");
include("../library/library.pager.php");

$productRepository = new ProductRepository();
$categoryRepository = new CategoryRepository();
$sectionRepository = new SectionRepository();
$lstProduct;
$perPageItem = 9;
$totalItems = 0;
$curPage = 1;
$category;
$section;
if (isset($_GET['page'])) {
    if (is_numeric($_GET['page']))
        $curPage = $_GET['page'];
}
if (isset($_GET["categoryID"])) {
    $lstProduct = $productRepository->GetProductFromCategory($_GET["categoryID"], $curPage, $perPageItem, $totalItems);
    $category = $categoryRepository->GetCategory($_GET["categoryID"]);
    $section = $sectionRepository->GetSection($category->SectionID_i);
}
else
    die("Category's unspecified");
$generateLink = GenerateLink($totalItems, 5, $perPageItem, $curPage);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

    <head>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
        <title>Cactus Flower</title>
        <link rel="stylesheet" type="text/css" href="../content/front-end.css" />
        <script type="text/javascript" src="../scripts/jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="../scripts/search.js"></script>
        <script type="text/javascript" src="../scripts/getproduct.js"></script>
    </head>

    <body>
        <div id="wrap">
<?php
include("../includes/frontend_Header.php");
include("../includes/frontend_Left.php");
?>
            <div id="right">
                <div class="box_content_t"></div>
                <div class="box_content_m">
                    <table border="0" width="100%" cellspacing="0" cellpadding="0"  class="cont_heading_table">
                        <tr>
                            <td><img src="../content/images/cont_heading_tl.gif" border="0" alt="" width="10" height="10" /></td>
                            <td  width="100%" class="cont_heading_t"><img src="../Content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                            <td><img src="../content/images/cont_heading_tr.gif" border="0" alt="" width="10" height="10" /></td>
                        </tr>

                        <tr>
                            <td  class="cont_heading_l"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                            <td  class="cont_heading_td"><a href="../Views/Index.php">HOME</a> &raquo; <a href="../Views/GetProdcutBySection.php?sectionID=<?php echo $section->ID_i; ?>"><?php echo $section->Name_s ?></a> &raquo; <?php echo $category->Name_s ?></td>
                            <td  class="cont_heading_r"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                        </tr>
                        <tr>
                            <td><img src="../content/images/cont_heading_bl.gif" border="0" alt="" width="10" height="10" /></td>
                            <td  class="cont_heading_b"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>

                            <td><img src="../content/images/cont_heading_br.gif" border="0" alt="" width="10" height="10" /></td>
                        </tr>
                    </table>
                    <div class="clearall"></div>
                    <div class="productContent">
                        <div class="loading"></div>
                        <div class="pagination pagination-left">
                            <div class="results">
                                <span>
                                    Kết quả từ: <?php echo (($curPage - 1) * $perPageItem + (count($lstProduct) > 0 ? 1 : 0)); ?> - <?php echo (($curPage - 1) * $perPageItem + count($lstProduct)); ?> của <?php echo $totalItems; ?>
                                </span>
                            </div>
                            <ul class="pager"><?php echo $generateLink ?></ul>
                        </div>
                        <div class="clearall"></div>
                        <!-- DEFINE YOUR CONTENT HERE -->

                        <table id="tblProducts" cellpadding="0" cellspacing="0">
<?php
            $count = 0;
            while ($count < count($lstProduct)) {
?>
                            <tr class='productsRow'>
                            <?php
                            for ($i = $count; $i < count($lstProduct); $i++) {
                            ?>
                                <td class="productCell" >
                                    <div><a class="link1" href="../views/detail.php?id=<?php echo $lstProduct[$i]->Code_s; ?>"><?php echo $lstProduct[$i]->Name_s ?></a></div>
                                    <div class="clearall" style="margin-top:10px;"></div>
                                    <div style="width:207px; text-align:center; border:1px solid #ebeaea; padding:5px 0 5px 0;">
                                        <a href="../views/detail.php?id=<?php echo $lstProduct[$i]->Code_s; ?>"><img class="product1" alt="" src="../content/images/Products/<?php echo $lstProduct[$i]->Code_s; ?>/<?php $spilit = explode('|', $lstProduct[$i]->ImageSrc_s);
                                echo $spilit[0]; ?>" /></a>
                                    </div>
                                    <div class="clearall" style="margin-top:10px;"></div>
                                    <div style="float:left; width:167px; padding:0 20px 0 20px;">
                                        <table cellpadding="0" cellspacing="0" border="0" class="cont_body_table_2" style="float:left; width:97px;">
                                            <tr>
                                                <td><img src="../content/images/cont_body_corn_tl_2.gif" border="0" alt="" width="10" height="10" /></td>
                                                <td width="100%" class="cont_body_tall_t_2"><img src="../../Content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                                                <td><img src="../content/images/cont_body_corn_tr_2.gif" border="0" alt="" width="10" height="10" /></td>
                                            </tr>
                                            <tr>

                                                <td class="cont_body_tall_l_2"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                                                <td width="100%" class="cont_body_td_2"><span class="productSpecialPrice"><?php echo $lstProduct[$i]->Price_f ?><br />VNĐ</span></td>
                                                <td class="cont_body_tall_r_2"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                                            </tr>
                                            <tr>
                                                <td><img src="../content/images/cont_body_corn_bl_2.gif" border="0" alt="" width="10" height="10" /></td>
                                                <td width="100%" class="cont_body_tall_b_2"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                                                <td><img src="../content/images/cont_body_corn_br_2.gif" border="0" alt="" width="10" height="10" /></td>
                                            </tr>
                                        </table>
                                        <div style="float:left; width:55px; margin:0 0 0 15px;">
                                            <a href="../views/detail.php?id=<?php echo $lstProduct[$i]->Code_s; ?>">
                                                <div class="detail">
                                                    Chi tiết
                                                </div>
                                            </a>
                                            <div class="clearall"></div>
                                            <a href="../views/Cart.php?id=<?php echo $lstProduct[$i]->Code_s; ?>">
                                                <div class="addToCart" style="margin:5px 0 0 0; cursor:pointer;">
                                                    Mua
                                                </div>
                                            </a>
                                        </div>
                                    </div>
                                </td>
<?php
                                if (++$count % 3 == 0)
                                    break;
                            }
?>
                            </tr>
<?php
                        }
?>
                        </table>
                        <!-- END DEFINE YOUR CONTENT HERE -->
                    </div>
                </div>
                <div class="box_content_b"></div>
            </div>
        </div>
<?php
                        include("../includes/frontend_footer.php");
?>
                        <script type="text/javascript">
                            $(document).ready(function(){
                                $("ul.pager > li > a").click(function () {
                                    GetProductByCategory($(this).attr("page"), "<?php echo $category->ID_i; ?>");
                });
            });
        </script>
    </body>

</html>

